package com.itheima.collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/*
删除集合中的元素
 */
public class Demo04_4 {
    public static void main(String[] args) {
        Collection<String> list= new ArrayList<>();

        list.add("test");
        list.add("test");
        list.add("张三");
        list.add("李四");
        list.add("test");
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()){
            String s = iterator.next();
            if("test".equals(s)){
              //  list.remove(s);
               // list.add("youyige");
                iterator.remove();
            }
        }

        System.out.println(list);
    }
}
